<?php
namespace app\models;
use yii\base\Model;

class OrderInfoSearch extends OrderInfo
{
    public $begin_time;
    public $end_time;

    public function rules()
    {
        return [
            ['begin_time', 'date', 'format'=>'yyyy-MM-dd', 'message' => 'begin_time非yyyy-MM-dd格式'],
            ['end_time', 'date', 'format'=>'yyyy-MM-dd', 'message' => 'end_time非yyyy-MM-dd格式'],

        ];
    }

    public function scenarios()
    {
        return Model::scenarios();
    }

    public function search($params)
    {
        $data['OrderInfoSearch'] = $params;
        // P($data);

        $query = OrderInfo::find();

        if (!($this->load($data) && $this->validate())) {
            // if($this->hasErrors()){
            //     P($this->getErrors());
            // }
            return false;
        }
        // P($this);

        if(isset($this->end_time) and !empty($this->end_time)){
            $this->end_time .= ' 23:59:59';
        }
        $query -> andFilterWhere(['>=', '{{%pj8_order_info}}.add_time', $this->begin_time])
               -> andFilterWhere(['<=', '{{%pj8_order_info}}.add_time', $this->end_time]);

        // P($query);
        return $query;
    }

    
}